<?php
    if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){exit();}
?>
<link rel="stylesheet" type="text/css" href="css/main.css">
<script src="js/sortable.js"></script>
<script type="text/javascript">
    function logOut() {
        $.ajax({
            type: "POST",
            url: "backend/logout.php"
        });
        $(".infofield").text("");
        $.each($(".widgetheading"), function(key, value) {
            if ($(value).data("clear") != null) {
                 $(value).data("clear")();
            }
        });
        clearNewUserForm();
        $("#wrap").hide();
        $("#footer").hide();
        var resp = $("#login_result");
        resp.attr("class", "info");
        resp.text("You have been successfully logged out.");
        resp.show(100).delay(100);
        login_overlay.eq(0).overlay().load();
    }
    
    function priceFormat(price) {
        var d = Math.floor(price / 100);
        var c = price % 100;
        if (c == 0) c = "00";
        else if (c < 10) c = "0" + c;
        return d + "." + c;
    }
    
    function helpwindow() {
        window.open("customer.html", "Online Help");
    }
</script>
<div id="wrap" <?php if (!isLoggedIn()) echo "style=\"display:none;\""; ?>>
    <div id="top"></div>
    <div id="content">
        <div>
            <div id="header" class="header">
                <h1> JWV Stock </h1>
                <h2> User Interface </h2>
                <button style="float:right;position: relative;top: -80px;right: 5px;" class="blue button" onclick="helpwindow();">Help</button>
            </div>
            <div style="clear:both;"></div>
            <table><tr>
                <td style="width: 100%;vertical-align: top;"><div class="middle">
                    <h2>Hello 
                        <div class="infofield" id="0">
                            <?php if (isLoggedIn()) 

                                echo $_SESSION['User']->FirstName . " " 
                                    . $_SESSION['User']->LastName . " (" 
                                    . $_SESSION['User']->UserName . ")"  
                            ?></div>!
                    </h2>
                    <br />
                    <div id='rec_stock_div' <?php if (isLoggedIn() && $_SESSION['User']->UserType != "Customer") {echo " style='display:none;' ";}?>>
                        <h2>Your recommended stocks: <span id='rec_stocks'></span></h2>
                    </div>
                    
                    <br/>
                    
                    <h2>Actions</h2>
                    
                    <br/>
                    <div id="NewUserButton"  <?php if (!isLoggedIn() || $_SESSION['User']->UserType == "Customer") echo "style=\"display:none;\""; ?>>
                        <input id='new_user' type="button" class="widgetheading" rel="#new_user_overlay" style="left:28px;height:32px;width:412px;" value=" Add a New User "/>
                    </div>
                    <?php include_once("new_user_form.php"); ?>
                    <br/>
                    
                    <?php include_once("widgets/employee_search_user_widget.php"); ?>
                    <?php include_once("widgets/create_order_form.php"); ?>
                    <?php include_once("widgets/employee_administrative_widget.php"); ?>
                    <?php
//                        if (isLoggedIn()) {
//                            if ($_SESSION['User']->UserType == "Customer") {
                    
                        include_once("widgets/customer_accounts.php");
                        //include_once("widgets/customer_orders.php");
//                            } else if (($_SESSION['User']->UserType == "Representative") || ($_SESSION['User']->UserType == "Manager")) {
//                                //include_once("widgets/representative_customerinfo.php");
//                            }
//                        }
                        include_once("widgets/stock_widget.php");
                    ?>
                    <!--
                    Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>
                    Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>
                    Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>
                    Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>

                    Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>
                    Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>
                    Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>
                    Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>Test!<hr/>
                    -->
                </div></td>
                <td style="width:200px;vertical-align: top;"><div class="right">
                    <h2> Your Info <a class="logout" onclick="logOut();return false;">Logout</a></h2>
                    <hr/>
                    <ul>
                        <li>User ID: 
                            <div class="infofield la" id="1"><?php if (isLoggedIn()) echo $_SESSION['User']->UserID ?></div>
                        </li>
                        <li>User Name: 
                            <div class="infofield la" id="2"><?php if (isLoggedIn()) echo $_SESSION['User']->UserName ?></div>
                        </li>
                        <li>Name: 
                            <div class="infofield la" id="3"><?php if (isLoggedIn()) echo $_SESSION['User']->FirstName . " " . $_SESSION['User']->LastName ?></div>
                        </li>
                        <li>User Type: 
                            <div class="infofield la" id="4"><?php if (isLoggedIn()) echo $_SESSION['User']->UserType ?></div>
                        </li>
                        <li>Address: 
                            <div class="infofield la" id="5""><?php if (isLoggedIn()) echo $_SESSION['User']->Address ?></div>
                        </li>
                        <li>City: 
                            <div class="infofield la" id="6"><?php if (isLoggedIn()) echo $_SESSION['User']->City ?></div>
                        </li>
                        <li>State: 
                            <div class="infofield la" id="7"><?php if (isLoggedIn()) echo $_SESSION['User']->State ?></div>
                        </li>
                        <li>Zip Code: 
                            <div class="infofield la" id="8"><?php if (isLoggedIn()) echo $_SESSION['User']->ZipCode ?></div>
                        </li>
                        <li>Telephone #: 
                            <div class="infofield la" id="9"><?php if (isLoggedIn()) echo $_SESSION['User']->TelephoneNumber ?></div>
                        </li>
                    </ul>
                </div></td>
            </tr></table>
        </div>
        <div id="clear"></div>
    </div>
    <div id="bottom"></div>
</div>

<div id="footer" <?php if (!isLoggedIn()) echo "style=\"display:none;\""; ?>>
    Design by <a href="http://www.minimalistic-design.net">Minimalistic Design</a>
</div>

<script type="text/javascript">
    function suggestStock() {
        $.ajax({
            type: 'POST',
            url: '../backend/suggest_stock.php',
            dataType: 'json',
            data: {},
            success: function(data) {
                var list = "";
                $.each(data, function(k, v) {list += v + " ";});
                $("#rec_stocks").text(list);
            }
        });
    }
    $(".widgetheading").click(
        function() {
            var widget = $(this).data("divlink");
            if (widget.is(":visible")) {
                widget.hide(); //widget.hide(500);
                $(this).find("img").attr("src", "images/plus.jpg");
            } else {
                widget.show(); //widget.show(500);
                $(this).find("img").attr("src", "images/minus.jpg");
            }
        }
    );
    $(".widget").hide();
    <?php if (isLoggedIn()) echo "doStockLookup('IBM, F, GM');" ?>
    <?php if (isLoggedIn() && $_SESSION['User']->UserType == "Customer") {echo "suggestStock();";} ?>
</script>